# 检测 segment.npy  是否超出 范围

import numpy as np
import os

def validate_labels(color_path, coord_path, segment_path, num_classes=10):
    try:
        color = np.load(color_path)
        coord = np.load(coord_path)
        segment = np.load(segment_path)
        
   
        # 颜色验证
        assert np.all(color >= 0) and np.all(color <= 255), "color值超出0-255范围"
        
        # 坐标验证
        assert not np.any(np.isnan(coord)), "coord包含NaN值"
        assert not np.any(np.isinf(coord)), "coord包含无限值"
        
        # 分割标签验证
        assert np.all(segment >= 0), "segment包含负值"
        assert np.all(segment < num_classes), f"segment值应小于{num_classes}"
        
        print("所有标签验证通过!")
        return True
        
    except Exception as e:
        print(f"验证失败: {str(e)}")
        print(segment_path)
        print(set(segment))
        return False

# 使用示例
data_path = "E:\\data\\3DpointCloud\\松霖人脸数据\\face_seg_clean"

data_list = os.listdir(data_path)

for i in data_list:
    file_list =  os.path.join(data_path, i)
    validate_labels(
        os.path.join(data_path, i, 'color.npy'), 
        os.path.join(data_path, i, 'coord.npy'),
        os.path.join(data_path, i, 'segment.npy'),
        num_classes=20)
    # break